package com.yonyou.cyxdms.sysAuth.service.controller.dealer;

import com.yonyou.cyx.framework.util.bean.ApplicationContextHelper;
import com.yonyou.cyxdms.framework.bean.dto.user_info.LoginInfoDto;
import com.yonyou.cyxdms.sysAuth.service.dto.dealer.MsgRecordDTO;
import com.yonyou.cyxdms.sysAuth.service.service.dealerchannel.MsgRecordService;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import com.yonyou.cyx.framework.controller.base.BaseController;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.HashMap;
import java.util.List;
import java.util.Map;


/**（×）
 * @author adu
 * @since 2019-09-12
 */
@RestController
@RequestMapping("/dealer/msgRecordManage")
public class MsgRecordManageController extends BaseController {
    private final Logger logger = LoggerFactory.getLogger(MsgRecordManageController.class);

    @Autowired
    public MsgRecordService msgRecordService;

    /**
     * 分页查询数据
     *
     * @param queryCondition 查询条件
     * @return com.baomidou.mybatisplus.core.metadata.IPage 分页对象
     * @author adu
     * @since 2019-09-12
     */
    @ResponseBody
    @GetMapping("/getNotice")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "员工id", name = "userId", required = true, dataType = "string", paramType = "header")
    })
    @ApiOperation(value = "公告分页查询-pc")
    public IPage<Map<String, Object>> getList(@RequestParam(value = "currentPage", defaultValue = "1") int currentPage,
                                              @RequestParam(value = "pageSize", defaultValue = "10") int pageSize, String msgTiteCont, String beginTime, String endTime, Integer noticeSource) {
        Page<Map<String, Object>> page = new Page(currentPage, pageSize);
        LoginInfoDto loginInfoDto = ApplicationContextHelper.getBeanByType(LoginInfoDto.class);
        Map<String, Object> queryCondition = new HashMap<>();
        queryCondition.put("userId", loginInfoDto.getUserId());
        queryCondition.put("msgTiteCont", msgTiteCont);
        queryCondition.put("beginTime", beginTime);
        queryCondition.put("endTime", endTime);
        queryCondition.put("noticeSource", noticeSource);
        return msgRecordService.selectPageNotice(page, queryCondition);
    }

    /**
     * ============================ 公告Notice维护====================
     * 公告维护-查询
     *
     * @param queryCondition 查询条件
     * @return com.baomidou.mybatisplus.core.metadata.IPage 分页对象
     * @author adu
     * @since 2019-10-11
     */
    @ResponseBody
    @GetMapping("/queryNotice")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "员工id", name = "userId", required = true, dataType = "string", paramType = "header")
    })
    @ApiOperation(value = "公告维护-查询PC-IOS")
    public IPage<Map<String, Object>> queryNotice(@RequestParam(value = "currentPage", defaultValue = "1") int currentPage,
                                                  @RequestParam(value = "pageSize", defaultValue = "10") int pageSize,
                                                  String msgTiteCont, String beginTime, String endTime, String beginTime1, String endTime1) {
        Page<Map<String, Object>> page = new Page(currentPage, pageSize);
        LoginInfoDto loginInfoDto = ApplicationContextHelper.getBeanByType(LoginInfoDto.class);
        Map<String, Object> queryCondition = new HashMap<>();
        queryCondition.put("appId", loginInfoDto.getAppId());
        queryCondition.put("userId", loginInfoDto.getUserId());
        queryCondition.put("msgTiteCont", msgTiteCont);
        queryCondition.put("beginTime", beginTime);
        queryCondition.put("endTime", endTime);
        queryCondition.put("beginTime1", beginTime1);
        queryCondition.put("endTime1", endTime1);
        return msgRecordService.queryNotice(page, queryCondition);
    }

    /**
     * 新增公告-pc
     */
    @PostMapping
    @ResponseStatus(HttpStatus.OK)
    @ApiImplicitParams({
            @ApiImplicitParam(value = "员工id", name = "userId", required = true, dataType = "string", paramType = "header")
    })
    @ApiOperation(value = "公告维护新增-PC(直接发布)")
    public Integer addMsgRecord(@RequestBody MsgRecordDTO msgRecordDTO) {
        logger.debug("msgTemplateDTO:{}", msgRecordDTO);
        return msgRecordService.addNotice(msgRecordDTO);
    }

    /**
     * 公告维护修改-pc
     *
     * @param msgId
     * @param msgRecordDTO
     */
    @ApiOperation(value = "公告维护编辑-PC")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "userId", name = "userId", required = true, dataType = "string", paramType = "header")
    })
    @PutMapping("/updateNotice")
    public void updateNotice(@RequestBody MsgRecordDTO msgRecordDTO) {
        msgRecordService.updateNotice(msgRecordDTO);
    }

    /**
     * 公告维护详情查看PC
     * adu
     */
    @GetMapping("/NoticeMaintain")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "员工id", name = "userId", required = true, dataType = "string", paramType = "header")
    })
    @ApiOperation(value = "公告维护详情-PC(是否确认)")
    public List<Map<String, String>> queryNoticeMaintain(@RequestParam Integer msgId) {
        return msgRecordService.queryNoticeMaintain(msgId);
    }

    /**
     * 已确认、待确认
     *
     * @param ids
     * @param orgDto
     */
    @ApiOperation(value = "公告确认发布-PC(确认)—IOS(收到)")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "userId", name = "userId", required = true, dataType = "string", paramType = "header")
    })
    @PutMapping("/updateStatus/{msgId}")
    public List<MsgRecordDTO> updateStatus(@PathVariable("msgId") Integer msgId, @RequestBody MsgRecordDTO msgRecordDTO) {
        return msgRecordService.updateStatus(msgId, msgRecordDTO);
    }


    @ApiOperation(value = "打印修改通知状态")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "userId", name = "userId", required = true, dataType = "string", paramType = "header")
    })
    @PutMapping("/printUpdateStatus")
    public void printUpdateStatus(@RequestBody List<MsgRecordDTO> msgRecordDTO) {
         msgRecordService.printUpdateStatus( msgRecordDTO);
    }


    /**
     * =================================================ios
     * 查询公告详情
     * adu
     */
    @GetMapping("/queryNotices/mobile")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "员工id", name = "userId", required = true, dataType = "string", paramType = "header")
    })
    @ApiOperation(value = "公告详情-IOS")
    public List<Map<String, String>> queryNotices(@RequestParam Integer msgId) {
        return msgRecordService.queryNotices(msgId);
    }

    /**
     * 查询公告详情ok
     * adu
     */
//    @GetMapping("/queryNotices")
//    @ApiImplicitParams({
//            @ApiImplicitParam(value = "员工id", name = "userId", required = true, dataType = "string", paramType = "header")
//    })
//    @ApiOperation(value = "公告列表查询-IOS")
//    public List<Map<String, String>> queryNoticesMobile() {
//        LoginInfoDto loginInfoDto = ApplicationContextHelper.getBeanByType(LoginInfoDto.class);
//        return msgRecordService.queryNoticesMobile(Math.toIntExact(loginInfoDto.getUserId()));
//    }

    /**
     * 清空公告ok
     *
     * @author duxiaoguang
     * @since 2019-09-04
     */
//    @DeleteMapping("/deleteAllGg")
//    @ResponseStatus(HttpStatus.OK)
//    @ApiImplicitParams({
//            @ApiImplicitParam(value = "员工id", name = "userId", required = true, dataType = "string", paramType = "header")
//    })
//    @ApiOperation(value = "清空公告-IOS")
//    public Integer deleteById() {
//        LoginInfoDto loginInfoDto = ApplicationContextHelper.getBeanByType(LoginInfoDto.class);
//        return msgRecordService.deleteByIdGg(Math.toIntExact(loginInfoDto.getUserId()));
//    }
    /**
     * 新增公告-客户关怀CC
     */
    @PostMapping("/customerAdd")
    @ResponseStatus(HttpStatus.OK)
    @ApiImplicitParams({
            @ApiImplicitParam(value = "员工id", name = "userId", required = true, dataType = "string", paramType = "header")
    })
    @ApiOperation(value = "新增公告-客户关怀CC(直接发布)")
    public Integer addmsgrecordcc(@RequestBody MsgRecordDTO msgRecordDTO) {
        logger.debug("msgTemplateDTO:{}", msgRecordDTO);
        return msgRecordService.addnoticecc(msgRecordDTO);
    }

}